﻿using System.Collections.Generic;
using Development.Tools;
using Development.Network.Msg;

namespace Development.Network
{
    public class MsgAction
    {
        protected delegate bool DelegateAction(MsgPacket packet);
        protected Dictionary<int, DelegateAction> m_procs = new Dictionary<int, DelegateAction>();

        public MsgAction()
        {
            RegisteProcess();
        }

        protected virtual void RegisteProcess()
        {

        }
        public virtual void OnPacket(MsgPacket packet)
        {
            DelegateAction func = null;
            if(m_procs.TryGetValue(packet.MsgId,out func))
            {
                func(packet);
            }
            else
            {
                if(packet.MsgId != 10)
                {
                    Log.WriteLog(ELogLevel.LOG_ERROR, "unknow msgid = " + packet.MsgId);
                }
            }
        }
    }
}
